<template>
  <div class="menu">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-button @click="$router.push({ name: 'menu-create' })"
          >添加菜单</el-button
        >
      </div>
      <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号">
      </el-table-column>
      <el-table-column
        prop="name"
        label="菜单名称"
        min-width="150">
      </el-table-column>
      <el-table-column
        prop="level"
        label="菜单级数"
        min-width="150">
      </el-table-column>
      <el-table-column
        prop="icon"
        label="前端图标"
        min-width="150">
      </el-table-column>
      <el-table-column
        prop="orderNum"
        label="排序"
        min-width="150">
      </el-table-column>
      <el-table-column
        prop="operatorId"
        label="操作"
        min-width="150">
        <template slot-scope="scope">
        <el-button
          size="mini"
          @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
      </el-table-column>
    </el-table>
    </el-card>
  </div>
</template>

<script lang="ts">
import Vue from 'vue'
import { deleteMenu, getAllMenuInfo } from '@/services/menu'

export default Vue.extend({
  name: 'MenuIndex',
  data () {
    return {
      tableData: []
    }
  },
  created () {
    this.loadingAllMenu()
  },
  methods: {
    async loadingAllMenu () {
      const { data } = await getAllMenuInfo()
      console.log(data)
      this.tableData = data.data
    },
    handleEdit (item: any, scro: any) {
      this.$router.push({
        name: 'menu-edit',
        params: {
          id: scro.id
        }
      })
    },
    handleDelete (index: number, item: any) {
      console.log(index, item)
      this.$confirm('确认删除吗？', '删除提示', {}).then(async () => {
        // 确认执行
        const { data } = await deleteMenu(item.id)
        if (data.code === '000000') {
          this.$message.success('删除成功')
          this.loadingAllMenu()
        }
      }).catch(() => {
        // 取消执行
        this.$message.info('已取消删除')
      })
    }
  }
})
</script>

<style lang="scss" scoped></style>
